<?php
/*................................................................ 
[七行 PHPCMS]                                        
 .  VERSION: 1.0                                                     
 .  Author: SevenEl sevenelement@qq.com                         
 .  Support: http://www.sevenel.cn   
................................................................*/
class Db
{
private $host;
private $user;
private $pwd;
private $dbname;
private $ConnId;
private $db_selected;
private $result;
private $new_link;
function __construct($name){
	$dbcfg=Sys::Gp(array('dbcfg',$name));
	$this->host = $dbcfg['host'];
	$this->user = $dbcfg['user'];
	$this->pwd = $dbcfg['psw'];
	$this->dbname = $dbcfg['database'];
	$this->new_link = $dbcfg['new_link'];
	$this->ConnId = mysql_connect($this->host,$this->user,$this->pwd,$this->new_link);
	if(!$this->ConnId){ 
		die('Sorry,Connect database false! '.mysql_error());
		}else{
		$this->db_selected = mysql_select_db($this->dbname,$this->ConnId);
		if(!$this->db_selected){
			die('Cannot select the database:'.mysql_error());
			}
		$this->result = mysql_query("set names '".$dbcfg['encode']."';");
		}
	}

function __destruct(){
	@mysql_free_result();
	@mysql_close($this->ConnId);
	}
function Desql($sql){//datebasExecuteSQL
	$this->result = mysql_query($sql);
	if(!$this->result){
		die('Cannot update the database: '.mysql_error());
		}
	}
function Dqsql($sql){//database QuerySQL
	$i = 0;
	$result_arr = array();
	$this->result = mysql_query($sql,$this->ConnId);
	if(!$this->result){
		die('Cannot view the database: '.mysql_error());
		}else{
		while($row = mysql_fetch_array($this->result)){
			$result_arr[$i++] = $row;
			}
		return $result_arr;
		mysql_free_result($this->result);
		}
	}
}
/*
$obj = new Db(array ('host' => 'localhost','user' => 'root', 'psw' => '123456','database'=> 'bibi','prefix' => 'lm', 'encode' => 'utf8' )); 
$result_arr=$obj->QuerySQL("select * from lm_ad where 1 limit 3"); 
print_r($result_arr);
*/ 
?>